/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.cggveritas.crewintranet.jms.utils.converter;

import fr.cggveritas.crewintranet.jms.dao.jpacontroller.CvPaysJpaController;
import fr.cggveritas.crewintranet.jms.entities.CvPays;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

/**
 *
 * @author ly01
 */
public class PaysConverter implements javax.faces.convert.Converter {

    private CvPaysJpaController cvPaysJpaController;

    public PaysConverter() {
        cvPaysJpaController = new CvPaysJpaController();
    }

    @Override
    public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
        //throw new UnsupportedOperationException("Not supported yet.");
        //Employe employe=new Employe(Long.parseLong(string));
//       System.out.println("value getAsObject : "+value);
//       System.out.println("lookupEmployeFacadeLocal() : "+lookupEmployeFacadeLocal());
        try {
            CvPays emp = cvPaysJpaController.findCvPays(Integer.parseInt(value));
            //System.out.println("Employe : "+emp);
            return emp;
        } catch (Exception ex) {
            //ex.printStackTrace(System.err);
        }
        return null;
    }

    @Override
    public String getAsString(FacesContext fc, UIComponent uic, Object value) {
        //System.out.println("value getAsString"+value);
        if (value != null && value instanceof CvPays) {
            return String.valueOf(((CvPays) value).getId());
        }
        return null;
    }
}
